import { pageData } from '../../util/util'
import { BaseService } from '@/base/base.service';
import { Injectable } from '@nestjs/common';
import { CreateLockServiceDto } from './dto/create-lock-service.dto';
import { UpdateLockServiceDto } from './dto/update-lock-service.dto';
import { lockService } from '@prisma/client';

@Injectable()
export class LockServiceService {

  constructor(private readonly baseService: BaseService) {}

  async create(createLockServiceDto: CreateLockServiceDto) {
    await this.baseService.lockService.create({
      data: {
        ...createLockServiceDto
      }
    })
    return '添加成功'
  }

  async findAll() {
    return await this.baseService.lockService.findMany();
  }

  async findPage(query: any) {
    return await pageData<lockService>('lockService', query)
  }

  async findOne(id: string) {
    return await this.baseService.lockService.findUnique({
      where: {
        id
      }
    })
  }

  async update(id: string, updateLockServiceDto: UpdateLockServiceDto) {
    await this.baseService.lockService.update({
      where: {
        id
      },
      data: updateLockServiceDto
    })
    return '修改成功'
  }

  async remove(id: string) {
    await this.baseService.lockService.delete({
      where: {
        id
      }
    })
    return '删除成功'
  }

  manyRemove(idList: string[]) {
    idList.forEach(async item => {
      await this.remove(item)
    })
    return '删除成功'
  }
}
